package com.csap.framework.integration.producer;

import com.aliyun.openservices.ons.api.SendCallback;
import com.aliyun.openservices.ons.api.SendResult;
import com.aliyun.openservices.ons.api.bean.ProducerBean;

/**
 * @author yangchengfu
 * @description rocketmq消息生产者
 * @dataTime 2020年-10月-12日 16:04:00
 **/
public class RocketmqProducer extends ProducerBean {
    /**
     * 发送异步消息
     *
     * @param body         消息内容
     * @param topic        订阅主题
     * @param tag          标签
     * @param key          消息key
     * @param msgId        消息ID
     * @param sendCallback 回调
     */
    public void sendAsync(final Object body, final String topic, final String tag, final String key, final String msgId, final SendCallback sendCallback) {
        sendAsync(RocketmqMessage.build()
                        .topic(topic)
                        .tag(tag)
                        .key(key)
                        .msgId(msgId)
                        .body(body)
                , sendCallback);
    }

    public void sendAsync(final String body, final String topic, final String tag, final String key, final String msgId, final SendCallback sendCallback) {
        sendAsync(RocketmqMessage.build()
                        .topic(topic)
                        .tag(tag)
                        .key(key)
                        .msgId(msgId)
                        .body(body)
                , sendCallback);
    }

    public void sendAsync(final byte[] body, final String topic, final String tag, final String key, final String msgId, final SendCallback sendCallback) {
        sendAsync(RocketmqMessage.build()
                        .topic(topic)
                        .tag(tag)
                        .key(key)
                        .msgId(msgId)
                        .body(body)
                , sendCallback);
    }

    /**
     * 发送消息-只发送不管结果
     *
     * @param body  消息内容
     * @param topic 订阅主题
     * @param tag   标签
     * @param key   消息key
     * @param msgId 消息ID
     */
    public void sendOneway(final Object body, final String topic, String tag, String key, String msgId) {
        sendOneway(RocketmqMessage.build()
                .topic(topic)
                .tag(tag)
                .key(key)
                .msgId(msgId)
                .body(body));
    }

    public void sendOneway(final String body, final String topic, String tag, String key, String msgId) {
        sendOneway(RocketmqMessage.build()
                .topic(topic)
                .tag(tag)
                .key(key)
                .msgId(msgId)
                .body(body));
    }

    public void sendOneway(final byte[] body, final String topic, String tag, String key, String msgId) {
        sendOneway(RocketmqMessage.build()
                .topic(topic)
                .tag(tag)
                .key(key)
                .msgId(msgId)
                .body(body));
    }

    /**
     * 发同步消息
     *
     * @param body  消息内容
     * @param topic 订阅主题
     * @param tag   标签
     * @param key   消息key
     * @param msgId 消息ID
     */
    public SendResult senMessage(final Object body, final String topic, String tag, String key, String msgId) {
        return send(RocketmqMessage.build()
                .topic(topic)
                .tag(tag)
                .key(key)
                .msgId(msgId)
                .body(body)
        );
    }

    public SendResult senMessage(final String body, final String topic, String tag, String key, String msgId) {
        return send(RocketmqMessage.build()
                .topic(topic)
                .tag(tag)
                .key(key)
                .msgId(msgId)
                .body(body)
        );
    }

    public SendResult senMessage(final byte[] body, final String topic, String tag, String key, String msgId) {
        return send(RocketmqMessage.build()
                .topic(topic)
                .tag(tag)
                .key(key)
                .msgId(msgId)
                .body(body)
        );
    }

    /**
     * 发送异步消息
     *
     * @param body  消息内容
     * @param topic 订阅主题
     * @param tag   标签
     * @param key   消息key
     */
    public void sendAsync(final Object body, final String topic, final String tag, final String key, final SendCallback sendCallback) {
        sendAsync(body, topic, tag, key, null, sendCallback);
    }

    public void sendAsync(final String body, final String topic, final String tag, final String key, final SendCallback sendCallback) {
        sendAsync(body, topic, tag, key, null, sendCallback);
    }

    public void sendAsync(final byte[] body, final String topic, final String tag, final String key, final SendCallback sendCallback) {
        sendAsync(body, topic, tag, key, null, sendCallback);
    }

    /**
     * 发送异步消息
     *
     * @param body         消息内容
     * @param topic        订阅主题
     * @param tag          标签
     * @param sendCallback 回调
     */
    public void sendAsync(final Object body, final String topic, final String tag, final SendCallback sendCallback) {
        sendAsync(body, topic, tag, null, null, sendCallback);
    }

    public void sendAsync(final String body, final String topic, final String tag, final SendCallback sendCallback) {
        sendAsync(body, topic, tag, null, null, sendCallback);
    }

    public void sendAsync(final byte[] body, final String topic, final String tag, final SendCallback sendCallback) {
        sendAsync(body, topic, tag, null, null, sendCallback);
    }

    /**
     * 发送消息-只发送不管结果
     *
     * @param body  消息内容
     * @param topic 订阅主题
     * @param tag   标签
     * @param key   消息key
     */
    public void sendOneway(final Object body, final String topic, final String tag, final String key) {
        sendOneway(body, topic, tag, key, null);
    }

    public void sendOneway(final String body, final String topic, final String tag, final String key) {
        sendOneway(body, topic, tag, key, null);
    }

    public void sendOneway(final byte[] body, final String topic, final String tag, final String key) {
        sendOneway(body, topic, tag, key, null);
    }

    /**
     * 发送消息-只发送不管结果
     *
     * @param body  消息内容
     * @param topic 订阅主题
     * @param tag   标签
     */
    public void sendOneway(final Object body, final String topic, final String tag) {
        sendOneway(body, topic, tag, null, null);
    }

    public void sendOneway(final String body, final String topic, final String tag) {
        sendOneway(body, topic, tag, null, null);
    }

    public void sendOneway(final byte[] body, final String topic, final String tag) {
        sendOneway(body, topic, tag, null, null);
    }

    /**
     * 发同步消息
     *
     * @param body  消息内容
     * @param topic 订阅主题
     * @param tag   标签
     * @param key   消息key
     * @return 发送结果，含消息Id, 消息主题
     */
    public SendResult senMessage(final Object body, final String topic, final String tag, final String key) {
        return senMessage(body, topic, tag, key, null);
    }

    public SendResult senMessage(final String body, final String topic, final String tag, final String key) {
        return senMessage(body, topic, tag, key, null);
    }

    public SendResult senMessage(final byte[] body, final String topic, final String tag, final String key) {
        return senMessage(body, topic, tag, key, null);
    }

    /**
     * 发同步消息
     *
     * @param body  消息内容
     * @param topic 订阅主题
     * @param tag   标签
     * @return 发送结果，含消息Id, 消息主题
     */
    public SendResult senMessage(final Object body, final String topic, final String tag) {
        return senMessage(body, topic, tag, null, null);
    }

    public SendResult senMessage(final String body, final String topic, final String tag) {
        return senMessage(body, topic, tag, null, null);
    }

    public SendResult senMessage(final byte[] body, final String topic, final String tag) {
        return senMessage(body, topic, tag, null, null);
    }
}
